package com.ym.ymplayer;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.ym.ymplayer.core.Constant;
import com.ym.ymplayer.view.YMPlayerView;

import java.util.ArrayList;
import java.util.List;

public class YMPlayerVideoActivity extends AppCompatActivity {
    public static String VIDEO_URL_KEY = "video_url_key";
    public static void start(Context context, String videoUrl) {
        Intent starter = new Intent(context, YMPlayerVideoActivity.class);
        starter.putExtra(VIDEO_URL_KEY, videoUrl);
        context.startActivity(starter);
    }

    private YMPlayerView videoView;
    private String videoUrl;
    private Button jump;
    private List<String> rtmpUrlList = new  ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zjk_video);
        videoUrl = getIntent().getStringExtra(VIDEO_URL_KEY);
        rtmpUrlList.add("http://africatv.live.net.sa:1935/live/africatv/playlist.m3u8");
        rtmpUrlList.add("rtmp://ns8.indexforce.com/home/mystream");

        videoView = findViewById(R.id.video_player);
        videoView.setVideoPath(videoUrl);
        videoView.start();

        jump = findViewById(R.id.jump);
        jump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                Constant.isPlay = !Constant.isPlay;
                if (Constant.isPlay) {
                    videoUrl = rtmpUrlList.get(0);
                } else {
                    videoUrl = rtmpUrlList.get(1);
                }
                Intent intent = new Intent(YMPlayerVideoActivity.this, YMPlayerVideoActivity.class);
                intent.putExtra(YMPlayerVideoActivity.VIDEO_URL_KEY, videoUrl);
                startActivity(intent);
            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        videoView.onDestroy();
    }

}